package net.csdn.business.common.constant;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @author likun
 * @date 2022/6/22 18:21
 */
public class RedisConstants {
    /**
     * key 过期时间配置 单位 秒
     */
    private static final Map<String, Integer> KEY_TO_TIMEOUT = Maps.newHashMap();

    public static final String SEP = "::";
    public static final String UNDERLINE = "_";
    public static final String STRIKE = "-";

    public static final String PROJECT = "pro";


    public static final String EXTEND_CONFIG = "extend_config";
    /**
     * 组织
     */
    public static final String ORG_COUNT = "org_count";
    public static final String USER_PROJECT_PERMISSION = "u_p_p";
    public static final String USER_ORG_ALL_PROJECT_IDS = "u_o_all_p_ids";
    public static final String PROJECT_MEMBER = "p_m";
    public static final String PROJECT_WITH_ORG_MEMBER = "p_w_o_m";
    public static final String PROJECT_MEMBER_ROLE = "p_m_r";
    public static final String PROJECT_ALL_MEMBER = "p_a_m";
    /**
     * issue相关
     */
    public static final String ISSUE = "issue";
    public static final String COMMENT = "comment";
    public static final String ISSUE_MEMBER = "issue_m";
    public static final String BATCH_QUERY_PROJECT_PAGE = "b_q_p_p";
    public static final String HOME_BANNER = "home_b";
    public static final String HOME_RECOMMENDED_ORG = "home_r_o";
    public static final String HOME_RECOMMENDED_PROJECT = "home_r_p";

    public static final String HOME_TOOLBAR = "home_toolbar";
    public static final String HOT_PROJECT_LIST = "h_p_l";
    /**
     * 举报组件，防止用户频繁提交，缓存记录提交间隔
     */
    public static final String REPORT_USER_KEY = "report:";
    public static final String REPORT_USER_LIMIT_KEY = "report:limit:";

    /**
     * 用户在组织下的角色信息缓存
     */
    public static final String USER_ORG_ROLE = "user_org_role";
    /**
     * 用户积分排行榜,日榜key
     */
    public static final String USER_RANK_DAY = "user:rank:day:";
    /**
     * 用户积分排行榜,周榜key
     */
    public static final String USER_RANK_WEEK = "user:rank:week:";

    /**
     * 用户积分排行榜,月榜key
     */
    public static final String USER_RANK_MONTH = "user:rank:month:";

    /**
     * 用户积分排行榜
     */
    public static final String USER_RANK = "user:rank:";


    /**
     * 用户加入的组织
     */
    public static final String USER_ORG = "user_org";
    /**
     * 组织基本信息缓存
     */
    public static final String ORG = "org";

    /**
     * 组织统计信息缓存
     */
    public static final String ORG_STATISTICS = "org_s";
    /**
     * 组织基本信息缓存
     */
    public static final String ORG_MEMBER = "org_m";
    /**
     * 组织基本信息缓存
     */
    public static final String ORG_BATCH_QUERY = "org:bacth:query";

    /**
     * 命名空间缓存
     */
    public static final String NAME_SPACE = "name_s";

    /**
     * 用户默认语言
     */
    public static final String USER_LANG = "user:lang";

    /**
     * 用户相关缓存
     */
    public final static String KEY_USER_ID = "user:id";
    public final static String KEY_USER_TOKEN = "user:token";

    public final static String KEY_USER_MFA_TMP_SECRET = "user:mfa:tmp:secret";
    public final static String KEY_USER_MFA_ENABLE = "user:mfa:enable";

    /**
     * 验证的mfa过程中，用户code换取的token缓存在redis中
     */
    public final static String MFA_VERIFY_LOGIN_INFO = "user:mfa:login";
    /**
     * 命名空间权益配置缓存
     */
    public final static String KEY_QUOTA = "quota";

    /**
     * 三方身份源
     */
    public final static String EXT_IDP_CONN = "extIdpConn";


    /**
     * 认证服务相关缓存
     */
    public final static String OAUTH2_CLIENT_INFO = "oauth:client";
    // public final static String OAUTH2_ACCESS_TOKEN = "oauth:act";
    public final static String OAUTH2_PERMMISSION = "oauth:per";

    /**
     * 关联组织查询子组织分页相关缓存
     */
    public final static String ORG_RELATION_PAGE = "org:relation:page:";
    public final static String CLA = "cla";
    public final static String CLA_APP = "cla_app";

    /**
     * 打赏记录缓存
     */
    public final static String USER_TIPS_RECORD = "user:tips:rec";


    /**
     * 精选项目分页相关缓存
     */
    public final static String PROJECT_SELECTED_PAGE = "project:s:p:";

    /**
     * 用户积分排行相关缓存
     */
    public static final String USER_SCORE_CAL = "user:score:cal";
    public static final String USER_RANK_INFO = "user:score:rank";
    /**
     * 用户页面排行榜配置信息
     */
    public static final String USER_RANK_PAGE_CONFIG = "user:score:page_config";
    /**
     * 关联组织查询子组织分页相关缓存
     */
    public final static String ORG_RELATION_CHILD_PAGE = "org:relation:children:page:";

    /**
     * 仓库所属组织id
     */
    public static final String PROJECT_TO_ORG = "p_t_r";
    /**
     * 敏感词检测缓存
     */
    public static final String SENSITIVE_WORD = "audit:sens";
    // 初始化map
    static {
        KEY_TO_TIMEOUT.put(PROJECT, 5*60);
        KEY_TO_TIMEOUT.put(USER_PROJECT_PERMISSION, 60);
        KEY_TO_TIMEOUT.put(USER_ORG_ALL_PROJECT_IDS, 60);
        KEY_TO_TIMEOUT.put(PROJECT_MEMBER, 120);
        KEY_TO_TIMEOUT.put(PROJECT_ALL_MEMBER, 120);
        KEY_TO_TIMEOUT.put(ISSUE, 120);
        /**
         * 用户加入的组织信息
         */
        KEY_TO_TIMEOUT.put(USER_ORG, 5 * 60);
        KEY_TO_TIMEOUT.put(ORG, 5 * 60);
        /**
         * 组织统计信息
         */
        KEY_TO_TIMEOUT.put(ORG_STATISTICS, 5 * 60);
        /**
         * 组织下成员列表
         */
        KEY_TO_TIMEOUT.put(ORG_MEMBER, 5 * 60);
        KEY_TO_TIMEOUT.put(ORG_BATCH_QUERY,30);
        /**
         * 用户缓存
         */
        KEY_TO_TIMEOUT.put(KEY_USER_ID, 12 * 60 * 60);
        KEY_TO_TIMEOUT.put(KEY_USER_MFA_TMP_SECRET, 24* 60 * 60);
        KEY_TO_TIMEOUT.put(KEY_USER_MFA_ENABLE, 7*24* 60 * 60);
        KEY_TO_TIMEOUT.put(MFA_VERIFY_LOGIN_INFO, 30* 60 * 60);

        /**
         * 命名空间权益配置缓存
         * 5分钟
         */
        KEY_TO_TIMEOUT.put(KEY_QUOTA, 5 * 60);
        /**
         * 用户默认语言，缓存五分钟
         * 5*60
         */
        KEY_TO_TIMEOUT.put(USER_LANG, 5*60);
        /**
         * 首页banner配置缓存
         * 5分钟
         */
        KEY_TO_TIMEOUT.put(HOME_BANNER, 5 * 60);
        /**
         * 首页推荐组织配置缓存
         * 5分钟
         */
        //KEY_TO_TIMEOUT.put(HOME_RECOMMENDED_ORG, 5 * 60);
        /**
         * 首页推荐组织配置缓存
         * 5分钟
         */
        KEY_TO_TIMEOUT.put(HOME_RECOMMENDED_PROJECT, 5 * 60);

        KEY_TO_TIMEOUT.put(ORG_COUNT, 90);

        KEY_TO_TIMEOUT.put(EXT_IDP_CONN, 5 * 60);
        /**
         * OAUTH2相关配置缓存
         * 5分钟
         */
        KEY_TO_TIMEOUT.put(OAUTH2_CLIENT_INFO, 72 * 60 * 60);
        // KEY_TO_TIMEOUT.put(OAUTH2_ACCESS_TOKEN, 5 * 60);
        KEY_TO_TIMEOUT.put(OAUTH2_PERMMISSION, 72 * 60 * 60);

        KEY_TO_TIMEOUT.put(CLA, 30 * 60);
        KEY_TO_TIMEOUT.put(CLA_APP, 60 * 60);
        /**
         * 组织、仓库、用户的扩展配置缓存
         * 7天
         */
        KEY_TO_TIMEOUT.put(EXTEND_CONFIG, 7*24*60 * 60);
        /**
         * 用户打赏记录,缓存5分钟
         */
        KEY_TO_TIMEOUT.put(USER_TIPS_RECORD, 5 * 60);
        KEY_TO_TIMEOUT.put(PROJECT_MEMBER_ROLE, 5 * 60);


        KEY_TO_TIMEOUT.put(USER_SCORE_CAL,  60 * 60);

        KEY_TO_TIMEOUT.put(USER_RANK_INFO,  5 * 60);

        KEY_TO_TIMEOUT.put(USER_RANK_PAGE_CONFIG, 5 * 60);
        KEY_TO_TIMEOUT.put(PROJECT_TO_ORG, 12*5 * 60);
        /**
         * 敏感词缓存30分钟
         */
        KEY_TO_TIMEOUT.put(SENSITIVE_WORD, 30 * 60);
    }

    public static Map<String, Integer> getKeyToTimeout() {
        return KEY_TO_TIMEOUT;
    }
}
